function [ outputfilter error_rate ] = run_vb_rsl( traintasks,testtasks,task,pca_dimensionality )
%-----------------------------------------------------
% Initialize, run and evaluate VB RSL model
% return outputfilter and error
%-----------------------------------------------------

 % switch the task-of-interest to be the first one...
  temptrain = traintasks;
  temptrain{1} = traintasks{task};
  temptrain{task} = traintasks{1};

  % train RSL with the switched tasks
  % 0.05 is the prior variance of parameters
  [posterior,prior] = initialize_rsl(temptrain, 0.05); 
  % 500 is number of iterations
  posterior2 = optimize_rsl(posterior, prior, temptrain, 500); 

  % predict for test data and evaluate
  classprobabilities = predict_rsl(posterior2, testtasks);
  classifications = -1 + 2*(classprobabilities > 0.5);
  classaccuracy = sum(classifications == testtasks(:,end))/size(testtasks,1);

  outputfilter = posterior2{2}(1:pca_dimensionality);
  error_rate = classaccuracy;


end

